package com.sky.consumer;


import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TimeoutOrdersConsumer {
    private static final String DELAY_QUEUE = "order_process_queue";

    @Autowired
    private OrderMapper orderMapper;

    @RabbitListener(queues =DELAY_QUEUE)
    public void handleOrderTimeout(Long orderId) {
        Integer status=orderMapper.checkOrderStatus(orderId);
        if(status==1)//还未付款
        {
            log.info("订单 {} 超时未支付，已取消",orderId);
            orderMapper.cancelOrder(orderId);
        }
    }

}
